import 'dart:convert';

import 'package:hongsheng/model/SPClassPointsProductEntity.dart';
import 'package:hongsheng/utils/SPClassCommonMethods.dart';
import 'package:hongsheng/utils/SPClassNavigatorUtils.dart';
import 'package:hongsheng/utils/colors.dart';
import 'package:hongsheng/widgets/SPClassToolBar.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:flutter_swiper_null_safety/flutter_swiper_null_safety.dart';

import 'SPClassInputInfo.dart';


//积分商品详情
class IntegralProductDetail extends StatefulWidget {
  final SPClassProduct ?data;
  const IntegralProductDetail({Key ?key, this.data}) : super(key: key);

  @override
  _IntegralProductDetailState createState() => _IntegralProductDetailState();
}

class _IntegralProductDetailState extends State<IntegralProductDetail> {
  String ?address;
  List detailImages = [];
  String ?type;

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar:SPClassToolBar(
        context,
        title: '商品详情',
      ),
      backgroundColor: Colors.white,
      bottomNavigationBar: bottomBtn(),
      body: SingleChildScrollView(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            // 轮播图
            Container(
              height: width(196),
              width: MediaQuery.of(context).size.width,
              child: Swiper(
                itemBuilder: (BuildContext context, int index) {
                  return ClipRRect(
                      child:Image.network(
                        widget.data?.spProBanner![index],
                        fit: BoxFit.cover,
                        width:MediaQuery.of(context).size.width,
                      )
                  );
                },
                onTap: (index) {},
                itemCount: widget.data!.spProBanner!.length,
                viewportFraction: 1,
                scale: 1,
                loop: false,
                autoplay: false,
              ),
            ),
            Container(
              padding: EdgeInsets.symmetric(
                  horizontal: width(15), vertical: width(10)),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  // 名称
                  Text(
                    '${widget.data!.spProProductName}',
                    style: TextStyle(
                      color: Color(0xFF333333),
                      fontSize: sp(13),
                    ),
                  ),
                  SizedBox(
                    height: width(4),
                  ),
                  Text(
                    '${widget.data!.spProPrice}积分',
                    style: TextStyle(
                      color: MyColors.main1,
                      fontSize: sp(13),
                    ),
                  ),

                ],
              ),
            ),
            Container(
              color: Color(0xFFF2F2F2),
              padding: EdgeInsets.symmetric(vertical: width(20)),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  Container(
                    height: width(1),
                    width: width(33),
                    color: Color(0XFF707070),
                  ),
                  SizedBox(
                    width: width(6),
                  ),
                  Text(
                    '商品详情',
                    style:
                        TextStyle(fontSize: sp(15), color: Color(0xFF666666)),
                  ),
                  SizedBox(
                    width: width(6),
                  ),
                  Container(
                    height: width(1),
                    width: width(33),
                    color: Color(0XFF707070),
                  ),
                ],
              ),
            ),
            productDetail(),
          ],
        ),
      ),
    );
  }

  Widget bottomBtn() {
    return SafeArea(
      bottom: true,
      child: Container(
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            GestureDetector(
              onTap: (){
                if(widget.data!.spProNum=='null'||widget.data!.spProNum=='0'){
                  return;
                }
                SPClassNavigatorUtils.spFunPushRoute(context, SPClassInputInfo(data: widget.data,));
              },
              child: Container(
                width: width(176),
                height: width(35),
                alignment: Alignment.center,
                decoration: BoxDecoration(
                  color: (widget.data!.spProNum=='null'||widget.data!.spProNum=='0')?MyColors.grey_cc:MyColors.main1,
                  borderRadius: BorderRadius.circular(150),
                ),
                child: Text((widget.data!.spProNum=='null'||widget.data!.spProNum=='0')?'缺货中':'立即兑换',style: TextStyle(color: Colors.white,fontSize: sp(15)),),
              ),
            )

          ],
        ),
      ),
    );
  }

  Widget productDetail(){
    return Container(
      child: Html(data: widget.data!.spProContent,),
    );
  }
}
